<?php

namespace mpend\controllers;

use Yii;
use mpend\components\Controller;
use common\exceptions\ModelHttpException;
use mpend\models\DeviceForm;
use mpend\models\SiteLogic;

/**
 * Site controller
 * Descriptions
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 * @date date time
 */
class SiteController extends Controller {

    public $filterAccessToken = false;

    /**
     * Declares the allowed HTTP verbs.
     * Please refer to [[VerbFilter::actions]] on how to declare the allowed verbs.
     *
     * @return array the allowed HTTP verbs.
     */
    protected function verbs() {
        return [
            '*' => ['GET'],
        ];
    }

    /**
     * Displays homepage.
     *
     * @return mixed
     */
    public function actionIndex() {
        return Yii::$app->name;
    }

    /**
     * 获取当前应用版本信息
     * @return mixed
     */
    public function actionVersion() {
        return [
            'build' => 20,
            'platform' => 'Andorid',
            'released' => '2.1.2',
            'instructions' => [
                '修复***错误',
            ],
        ];
    }

    /**
     * 注册设备信息（推送消息时使用）
     *
     * @return mixed
     */
    public function actionRegister() {
        $model = new DeviceForm();
        if (!$model->load(Yii::$app->request->post(), '')) {
            throw new ModelHttpException('提交时数据未加载成功');
        }
        $model->device = $this->token->device;
        return $model->register();
    }

}
